﻿package com.mini.framework.bi.bpull.chart;

import java.util.ArrayList;
import java.util.List;

import com.mini.framework.bi.bpull.model.Bar;

/**
 * 
 * @author lishsh
 *
 */
public class BarChart extends Chart{
	
	
	private String convertType;//目录统一为‘average’
	
	
	private List<Bar> records;//数据.

	public String getConvertType() {
		return convertType;
	}

	public void setConvertType(String convertType) {
		this.convertType = convertType;
	}

	

	public List<Bar> getRecords() {
		return records;
	}

	public void setRecords(List<Bar> records) {
		this.records = records;
	}
	
	public String getXml(){
		final String newLine = "\r\n";
		StringBuilder sb = new StringBuilder();
		sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
		sb.append("<data converType=\""+this.getConvertType()+"\" tag1=\"" +this.getTag1() +"\" ");
		if(this.getTag2() != null){
			sb.append("tag2=\""+this.getTag2()+"\"");
		}
		if(this.getTag3() != null){
			sb.append(" tag3=\""+this.getTag3()+"\"");
		}
		sb.append(">");
		sb.append(newLine);
		for(Bar bar:records){
			sb.append("<record unique=\"" +bar.getUnique()+"\" overTag=\"" +bar.getOverTag() +"\" xAxisTag=\""+bar.getXAxisTag()+"\" data1=\""+bar.getData1()+"\" ");
			if(bar.getData2() !=null){
				sb.append(" data2=\"" +bar.getData2()+"\"");
			}
			if(bar.getData3() !=null){
				sb.append(" data3=\"" +bar.getData3()+"\"");
			}
			sb.append("/>");
			sb.append(newLine);
		}
		sb.append("</data>");
		return sb.toString();
	}
	
	public static void main(String arg[]){
		List<Bar> bars = new ArrayList<Bar>();
		Bar bar1 = new Bar();
		bar1.setUnique("1");
		bar1.setOverTag("google");
		bar1.setXAxisTag("google");
		bar1.setData1("100");
		bars.add(bar1);
		BarChart chart = new BarChart();
		chart.setConvertType("average");
		chart.setRecords(bars);
		chart.setTag1("test");
		System.out.println(chart.getXml());
	}
	
	

}
